package com.yoomiito.app.ui.search.youpin

import cn.droidlover.xdroidmvp.net.ApiException
import cn.droidlover.xdroidmvp.net.ApiSubscriber
import cn.droidlover.xdroidmvp.net.XApi
import com.yoomiito.app.base.AppConfig
import com.yoomiito.app.base.BaseActPresenter
import com.yoomiito.app.model.gift.GiftGoodsList
import com.yoomiito.app.net.YmApi

class YouPinSearchResultPresenter(appConfig: AppConfig) : BaseActPresenter<YouPinSearchResultActivity>(appConfig) {

    fun searchGoods(key: String,sort: String, page: Int) {
        YmApi.getYmService()
                .getVipGiftGoods(sort, page, 0, 3, key)
                .compose(v?.bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(object : ApiSubscriber<GiftGoodsList>(handleException()) {
                    override fun onSuccess(giftGoodsList: GiftGoodsList) {
                        if (hasV()) {
                            v?.dismissLoading()
                            v?.setData(giftGoodsList.list)
                        }
                    }

                    override fun onFail(error: ApiException) {
                        if (hasV()) {
                            v.dismissLoading()
                        }
                    }
                })
    }
}